package cn.codeforfun.controller;

import cn.codeforfun.entity.User;
import cn.codeforfun.util.OKHttpUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * Package cn.codeforfun.controller
 * Project framework-demo
 * Author WangBin
 * Email bin.wang12@pactera.com
 * Created on 2017/5/3 16:40
 * version 1.0.0
 */
@RestController
@RequestMapping("/test1")
public class TestController1 {
  @RequestMapping("/post")
  public String post() {
    try {
      User user = new User();
      user.setId(2L);
      user.setUsername("BBB");
      user.setPassword("bbb");
      String post = OKHttpUtil.post("http://localhost:8080/test2/post", user);
      return post;
    } catch (IOException e) {
      e.printStackTrace();
      return "error";
    }
  }

  @RequestMapping("/get")
  public String get() {
    try {
      String get = OKHttpUtil.get("http://localhost:8080/test2/get?aaa=1&bbb=2");
      return get;
    } catch (IOException e) {
      e.printStackTrace();
      return "error";
    }
  }
}
